package top.yokey.shopnc.activity.mine;

import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.LinearLayoutCompat;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.RelativeLayout;

import top.yokey.shopnc.R;
import top.yokey.shopnc.activity.main.MainActivity;
import top.yokey.shopnc.base.BaseApplication;
import top.yokey.shopnc.base.BaseConstant;
import top.yokey.base.base.BaseHttpClient;
import top.yokey.base.base.BaseShared;
import top.yokey.base.base.BaseSnackBar;
import top.yokey.base.base.BaseToast;
import top.yokey.shopnc.base.SwipeActivity;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;

@ContentView(R.layout.activity_mine_setting)
public class SettingActivity extends SwipeActivity {

    @ViewInject(R.id.mainLinearLayout)
    private LinearLayoutCompat mainLinearLayout;
    @ViewInject(R.id.mainToolbar)
    private Toolbar mainToolbar;

    @ViewInject(R.id.passwordRelativeLayout)
    private RelativeLayout passwordRelativeLayout;
    @ViewInject(R.id.mobileRelativeLayout)
    private RelativeLayout mobileRelativeLayout;
    @ViewInject(R.id.payPassRelativeLayout)
    private RelativeLayout payPassRelativeLayout;
    @ViewInject(R.id.feedbackRelativeLayout)
    private RelativeLayout feedbackRelativeLayout;

    @ViewInject(R.id.logoutTextView)
    private AppCompatTextView logoutTextView;

    private long logoutTimeLong;

    @Override
    public void initData() {

        logoutTimeLong = 0L;

        setToolbar(mainToolbar, "设置");

    }

    @Override
    public void initEven() {

        passwordRelativeLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                BaseApplication.get().startCheckMobile(getActivity(), PasswordActivity.class);
            }
        });

        mobileRelativeLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                BaseApplication.get().startCheckMobile(getActivity(), ModifyMobileActivity.class);
            }
        });

        payPassRelativeLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                BaseApplication.get().startCheckMobile(getActivity(), PayPassActivity.class);
            }
        });

        feedbackRelativeLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                BaseApplication.get().startCheckLogin(getActivity(), FeedbackActivity.class);
            }
        });

        logoutTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                logout();
            }
        });

    }

    //自定义方法

    private void logout() {

        if (System.currentTimeMillis() - logoutTimeLong > BaseConstant.TIME_EXIT) {
            BaseSnackBar.get().show(mainLinearLayout, "再按一次注销登录...");
            logoutTimeLong = System.currentTimeMillis();
        } else {
            BaseHttpClient.get().updateKey("");
            BaseToast.get().show("注销成功！");
            BaseShared.get().putString(BaseConstant.SHARED_KEY, "");
            BaseApplication.get().start(getActivity(), MainActivity.class);
            BaseApplication.get().finish(getActivity());
        }

    }

}
